{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 提示词 #\n",
    "from openai import OpenAI\n",
    "\n",
    "client = OpenAI(\n",
    "    #api_key=os.getenv(\"DASHSCOPE_API_KEY\"),\n",
    "    # api_key=\"sk-b571bfbe652b4ec68ac0491e33949622\", # 这种写法不好，泄露了api-key。 回头正式部署时改掉。\n",
    "    # base_url=\"https://dashscope.aliyuncs.com/compatible-mode/v1\",\n",
    "    api_key=\"ollama\",\n",
    "    base_url=\"http://192.168.20.43:11434/v1\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "    \"question_1\": \"需要提交哪些具体的文件来完成差旅报销？\",\n",
      "    \"question_2\": \"能否提供一份关于差旅报销的详细步骤指南？\",\n",
      "    \"question_3\": \"如何在系统中准确填写差旅报销申请，确保信息无误？\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "def llm_3questions_prompt(context_str):\n",
    "    system_prompt = \"\"\n",
    "\n",
    "    prompt = f\"\"\"\n",
    "    你是一个推荐系统，你需要基于过往聊天的Context来围绕兴趣点推荐3个用户紧接着最有可能问的问题。\n",
    "\n",
    "    这些问题需要遵循如下规则：\n",
    "    1. 问题不能是已经问过的问题，不能是已经回答过的问题，问题必须和用户最后一轮的问题紧密相关，可以适当延伸；\n",
    "    2. 每个问题应具有足够的区分度，且只包含一个问题或者指令；\n",
    "    3. 问题应站在用户的视角提出；\n",
    "    4. 问题尽量简洁，不应超过20个字；\n",
    "    5. 如果对话涉及政治敏感、违法违规、暴力伤害、违反公序良俗类内容，你应该拒绝推荐问题。\n",
    "\n",
    "    Follow the OUTPUT FORMAT.\n",
    "    ---------------------\n",
    "    # Context #\n",
    "    {context_str}\n",
    "    ---------------------\n",
    "    # OUTPUT FORMAT #\n",
    "    {{\n",
    "        \"question_1\": \"some text\",\n",
    "        \"question_2\": \"some text\",\n",
    "        \"question_3\": \"some text\"\n",
    "    }}\n",
    "    \"\"\"\n",
    "\n",
    "    completion = client.chat.completions.create(\n",
    "        model=\"qwen2-7b-instruct\",\n",
    "        messages=[{'role': 'system', 'content': system_prompt},\n",
    "                  {'role': 'user', 'content': prompt}],\n",
    "        )\n",
    "    return completion.choices[0].message.content\n",
    "\n",
    "# 测试用例\n",
    "context_str = \"\"\"\n",
    "    User：差旅报销流程是什么\n",
    "    AI：差旅报销流程如下......\n",
    "\"\"\"\n",
    "summary_text = llm_3questions_prompt(context_str) \n",
    "print(summary_text)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
